package com.erpanderp.wam.usm.view.projectandassignment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import javax.servlet.http.HttpSession;

import org.primefaces.component.datatable.DataTable;

import com.erpanderp.wam.ac.model.entity.project.ProjectAssignmentDetail;
import com.erpanderp.wam.adm.model.entity.SAPERPModule;
import com.erpanderp.wam.adm.model.service.SAPERPModuleDAO;
import com.erpanderp.wam.usm.model.entity.projectandassignment.EmployeeProject;
import com.erpanderp.wam.usm.model.entity.projectandassignment.Project;
import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.usm.model.service.projectandassignment.EmployeeProjectDAO;
import com.erpanderp.wam.usm.model.service.projectandassignment.ProjectDAO;
import com.erpanderp.wam.usm.model.service.user.EmployeeDAO;
import com.erpanderp.wam.util.CommonLookup;
@ManagedBean
@ViewScoped
public class EmployeeProjectAssignmentsBean implements Serializable {

private static final long serialVersionUID = 1L;
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);

ProjectDAO projectDAO = new ProjectDAO();
EmployeeDAO employeeDAO = new EmployeeDAO();
EmployeeProjectDAO employeeProjectDAO = new EmployeeProjectDAO();

private DataTable dataTable;
private DataTable EmployeeAssignedProjects;
private Project project = new Project();
private SAPERPModuleDAO sapERPModuleDAO = new SAPERPModuleDAO();
private EmployeeProject employeeProject = new EmployeeProject();
private WAMUser wamUser = new WAMUser();

private List<Project> projectsList = new ArrayList<Project>();
private List<SAPERPModule> modulesList = new ArrayList<SAPERPModule>();
private Map<String, String> modulesMap = new HashMap<String, String>();
private List<EmployeeProject> employeeProjects = new ArrayList<EmployeeProject>();
	

private String selectedModuleName;
private Long selectedEmployeeId;


private SAPERPModule selectedModule = new SAPERPModule();
private Employee employee = new Employee();



public EmployeeProjectAssignmentsBean()
{
	System.out.println("ASSIGN PROJECT BEAN");
	setWamUser((WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER));
	projectsList = projectDAO.getAllProjects();
}
public String showEmployeeProjectAssignmentAction() 
{
System.out.println("showEmployeeProjectAssignmentAction..................");
employeeProjects.clear();
project = (Project) dataTable.getRowData();

System.out.println("showEmployeeProjectAssignmentAction.................."+project.getProjectId());

employeeProjects.addAll(employeeProjectDAO.getAllEmployeeProjectDetailsByProjectId(project.getProjectId(),CommonLookup.STATUS_ACTIVE));
employeeProject = employeeProjects.get(0);
//employeeProjects.clear();

return null;
}

public String deleteEmployeeProjectAssignmentAction() 
{
System.out.println("deleteEmployeeProjectAssignmentAction..................");
employeeProject = (EmployeeProject) EmployeeAssignedProjects.getRowData();

System.out.println("showEmployeeProjectAssignmentAction.................."+project.getProjectId());
employeeProject.setStatus(CommonLookup.STATUS_INACTIVE);
employeeProject = employeeProjectDAO.deleteEmployeeProject(employeeProject);
return null;
}

//GETTERS AND SETTERS
public List<Project> getProjectsList() {
	return projectsList;
}

public void setProjectsList(List<Project> projectsList) {
	this.projectsList = projectsList;
}

public Project getProject() {
	return project;
}

public void setProject(Project project) {
	this.project = project;
}
public List<SAPERPModule> getModulesList() {
	return modulesList;
}

public void setModulesList(List<SAPERPModule> modulesList) {
	this.modulesList = modulesList;
}

public SAPERPModuleDAO getSapERPModuleDAO() {
	return sapERPModuleDAO;
}

public void setSapERPModuleDAO(SAPERPModuleDAO sapERPModuleDAO) {
	this.sapERPModuleDAO = sapERPModuleDAO;
}
public ProjectDAO getProjectDAO() {
	return projectDAO;
}

public void setProjectDAO(ProjectDAO projectDAO) {
	this.projectDAO = projectDAO;
}
public Long getSelectedEmployeeId() {
	return selectedEmployeeId;
}

public void setSelectedEmployeeId(Long selectedEmployeeId) {
	this.selectedEmployeeId = selectedEmployeeId;
}
public Employee getEmployee() {
	return employee;
}

public void setEmployee(Employee employee) {
	this.employee = employee;
}

public SAPERPModule getSelectedModule() {
	return selectedModule;
}

public void setSelectedModule(SAPERPModule selectedModule) {
	this.selectedModule = selectedModule;
}
public EmployeeDAO getEmployeeDAO() {
	return employeeDAO;
}

public void setEmployeeDAO(EmployeeDAO employeeDAO) {
	this.employeeDAO = employeeDAO;
}

public Map<String, String> getModulesMap() {
	return modulesMap;
}

public void setModulesMap(Map<String, String> modulesMap) {
	this.modulesMap = modulesMap;
}
public String getSelectedModuleName() {
	return selectedModuleName;
}

public void setSelectedModuleName(String selectedModuleName) {
	this.selectedModuleName = selectedModuleName;
}





public EmployeeProject getEmployeeProject() {
	return employeeProject;
}





public void setEmployeeProject(EmployeeProject employeeProject) {
	this.employeeProject = employeeProject;
}
public EmployeeProjectDAO getEmployeeProjectDAO() {
	return employeeProjectDAO;
}





public void setEmployeeProjectDAO(EmployeeProjectDAO employeeProjectDAO) {
	this.employeeProjectDAO = employeeProjectDAO;
}

public HttpSession getSession() {
	return session;
}





public void setSession(HttpSession session) {
	this.session = session;
}





public WAMUser getWamUser() {
	return wamUser;
}





public void setWamUser(WAMUser wamUser) {
	this.wamUser = wamUser;
}







public DataTable getDataTable() {
	return dataTable;
}





public void setDataTable(DataTable dataTable) {
	this.dataTable = dataTable;
}
public static long getSerialversionuid() {
	return serialVersionUID;
}
public DataTable getEmployeeAssignedProjects() {
	return EmployeeAssignedProjects;
}
public void setEmployeeAssignedProjects(DataTable employeeAssignedProjects) {
	EmployeeAssignedProjects = employeeAssignedProjects;
}
public List<EmployeeProject> getEmployeeProjects() {
	return employeeProjects;
}
public void setEmployeeProjects(List<EmployeeProject> employeeProjects) {
	this.employeeProjects = employeeProjects;
}



}
